package eu.dominicum.ft.ui.web.jsf.view.bean;

import eu.dominicum.ft.pd.FantasyTour;
import eu.dominicum.ft.pd.boundary.FantasyTourManagement;
import eu.dominicum.ft.pd.mao.MakeFantasyTourMAO;
import org.apache.myfaces.trinidad.context.RequestContext;

import javax.ejb.EJBException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;

/**
 * Backing bean for the MakeFantasyTourDialog view.
 *
 * @author Harry Klerks
 * @since 2013M1
 */
@ManagedBean(name = "makeFantasyTourDialog")
@ViewScoped
public final class MakeFantasyTourDialogBean {

    /**
     * {@link FantasyTourManagement}.
     */
    @Inject
    private FantasyTourManagement fantasyTourManagement;

    /**
     * {@link MakeFantasyTourMAO}.
     */
    @Inject
    private MakeFantasyTourMAO makeFantasyTourMAO;

    /**
     * .
     *
     * @return MakeFantasyTourMAO
     */
    public MakeFantasyTourMAO getMakeFantasyTourMAO() {
        return makeFantasyTourMAO;
    }

    /**
     * .
     *
     * @param newMakeFantasyTourMAO -
     */
    public void setMakeFantasyTourMAO(final MakeFantasyTourMAO newMakeFantasyTourMAO) {
        this.makeFantasyTourMAO = newMakeFantasyTourMAO;
    }

    /**
     * Event handler for the Maak-buttonclick.
     *
     * @param actionEvent -
     */
    public void makeFantasyTour(final ActionEvent actionEvent) {

        try {
            FantasyTour fantasyTour = this.fantasyTourManagement.makeFantasyTour(this.makeFantasyTourMAO);
            RequestContext.getCurrentInstance().returnFromDialog(fantasyTour, null);
        } catch (EJBException eex) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    eex.getMessage(), null));

        }
    }
}
